<template>
	<view class="content">
		<navTop :title="navtop.title" :isHeight="false" :tipsShow="false" hasBgc="#fff" :color="navtop.color" :isBack="true" ></navTop>
		<view class="content-box" :style="{paddingTop:barHeight+'rpx'}">
		</view>
		<view class="content-body">
			<view class="view-top__title">
				<image :src="userInfo.head || wxInfo.avatarUrl" mode="" class="view-user__img"></image>
				<view class="view-user__center">
					<view class="flex-l">
						<text class="view-sex__text">{{userInfo.name || wxInfo.nikeName || ''}}</text>
						<image v-if="userInfo.gender == 1" :src="me_male" mode="" class="view-sex__img"></image>
						<image v-if="userInfo.gender == 2" :src="me_list_female" mode="" class="view-sex__img"></image>
					</view>
					<view class="view-sex__text-info">
						{{userInfo.location || wxInfo.city || ' '}}
					</view>
					<view class="view-nums">
						<view class="view-nums__item">
							<view class="view-nums__item-num">
								{{staticInfo.posts || 0}}
							</view>
							<view class="view-nums__item-title">
								Posts
							</view>
						</view>
						<view class="view-nums__item" @click="gotoFollow(0)">
							<view class="view-nums__item-num">
								{{staticInfo.following || 0}}
							</view>
							<view class="view-nums__item-title">
								Following
							</view>
						</view>
						<view class="view-nums__item" @click="gotoFollow(1)">
							<view class="view-nums__item-num">
								{{staticInfo.follower || 0}}
							</view>
							<view class="view-nums__item-title">
								Follower
							</view>
						</view>
					</view>
				</view>
					<view class="view-user__btn" @click="followUser">
						{{userInfo.followState ? 'unFollow' : 'Follow'}}
					</view>
			</view>
			
			<view class="content-list" v-if="squareList && squareList.length">
				<view class="content-item" v-for="(v, i) in squareList" :key="i" @click="gotoPage(v)">
					<view class="content-list__official" v-if="v.isOfficial">
						<image :src="official" mode="" class="content-list__o"></image>
						<text class="content-list__t">official</text>
					</view>
					<view class="content-list__title">
						<image :src="v.accountHead"  mode="aspectFit" class="content-list__title-img"></image>
						<view>
							<view>{{v.accountName}}</view>
							<text class="content-list__title-time">{{v.tips}}</text>
						</view>
					</view>
					<view class="content-list__text">
						{{v.content || ''}}
					</view>
					<view class="content-list__imgs">
						<image :src="item.imgUrl"  mode="aspectFit" class="content-list__imgs-item" v-for="(item, index) in v.imgList" :key="index" @click.stop="searchImg(index, v.imgList)">
						</image>
					</view>
					<view class="content-list__btns" @click.stop="addLike(v)">
						<image :src="v.isLike ? like : notLike" mode="" class="content-list__btns-img"></image>
						<text>{{v.likes || 0}}</text>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>
<script>
import navTop from '@/components/nav-title.vue';
import like from '@/static/like.png'
import notLike from '@/static/not-like.png'
import me_male from '@/static/me_male.png'
import me_list_female from '@/static/me_list_female.png'

	export default {
		components: {
			navTop
		},
		data() {
			return {
				like,
				notLike,
				me_male,
				me_list_female,
				barHeight: 0,
				navtop: {
					title: 'User Detail',
					color: '#000'
				},
				userInfo: {},
				staticInfo: {},
				squareList: []
			}
		},
		onLoad(e) {
			this.getUser(e.id)
		},
		created() {
			this.isBarHeight999().then((statusBarHeight)=>{
				this.barHeight = statusBarHeight + 180
			})
		},
		methods: {
			getUser(id) {
				this.$http('get', '/app/account/statics', {
					accountId: id
				}).then((res) => {
					if (res.success) {
						console.log(res.data)
						this.staticInfo = res.data
						this.userInfo = res.data.account
						this.getSquare()
					}
				})
			},
			followUser() {
				this.$http('post', '/app/follow', {
					accountId: this.userInfo.id
				}, {
					'Content-Type': 'application/x-www-form-urlencoded'
				}).then((res) => {
					if (res.success) {
						if (this.userInfo.followState == 1) {
							this.userInfo.followState = 0
						} else {
							this.userInfo.followState = 1
						}
					}
				})
			},		
			gotoPage(v) {
				uni.navigateTo({
					url: `/pages/square/details?id=${v.id}`
				});
			},				
			getSquare() {
				this.$http('get', '/app/dynamic/list', {
					page: 1,
					limt: 9999,
					accountId: this.userInfo.id
				}).then(res => {
					if (res.success) {
						res.data.forEach((v) => {
							v.tips = this.$utils.getTimerOff(v.createTime)
						})
						this.squareList = res.data
					}
				})
			},
			addLike(v) {
				this.$http('get', '/app/thumbs', {
					dynamicId: v.id
				}).then((res) => {
					if (res.success) {
						if (v.isLike == 1) {
							v.isLike = 0
							v.likes -= 1
						} else {
							v.isLike = 1
							v.likes += 1
						}
					}
				})
			}
		}
	}
</script>

<style lang="less">
.content {
	background-color: #fff;
	// padding: 0 30px;
	min-height: 100vh;
}
.content-box {
	font-size: 40rpx;
	font-family: Helvetica-Bold, Helvetica;
	font-weight: bold;
	color: #1F1F1F;
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 34rpx;
	padding: 0 40rpx;
	.content-box__btn {
		display: inline-block;
		padding: 16rpx 32rpx;
		font-size: 28rpx;
		color: #fff;
		background: #0078FF;
		border-radius: 18px;
	}
}
.content-body {
	
}
.view-top__title {
	font-size: 64rpx;
	font-family: PingFangSC-Semibold, PingFang SC;
	font-weight: 600;
	box-sizing: border-box;
	padding: 0 30rpx;
	// color: #FFFFFF;
	box-sizing: border-box;
	// padding-right: 30rpx;
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 190rpx;
	box-shadow: 0px 0px 0px 0px #EEEEEE;
}
.view-user__img {
	width: 128rpx;
	height: 128rpx;
	border-radius: 50%;
}
.view-user__center{
	width: 396rpx;
	padding: 0 24rpx;
	box-sizing: border-box;
	position: relative;
	.view-sex__text {
		font-size: 48rpx;
		font-family: Helvetica-Bold, Helvetica;
		font-weight: bold;
		// color: #FFFFFF;
		margin: 0 16rpx 8rpx 0;
	}
	.view-sex__img {
		width: 32rpx;
		height: 32rpx;
	}
	.view-sex__text-info {
		box-sizing: border-box;
		padding: 6rpx 0 0 0;
		font-size: 26rpx;
		font-family: Helvetica;
		color: rgba(0, 0, 0, 0.65);
	}
	.view-nums {
		position: absolute;
		font-size: 32rpx;
		top: 130rpx;
		left: 0;
		right: 0;
		display: flex;
		box-sizing: border-box;
		padding: 0 30rpx;
		justify-content: space-between;
		align-items: flex-start;
		margin-top: 34rpx;
	}
	.view-nums__item {
		text-align: left;
	}
	.view-nums__item-num {
		font-size: 32rpx;
		font-family: Helvetica-Bold, Helvetica;
		font-weight: bold;
		// color: #FFFFFF;
		margin-bottom: 10rpx;
	}
	.view-nums__item-title {
		font-size: 22rpx;
		font-family: Helvetica-Light, Helvetica;
		font-weight: 300;
		color: rgba(31, 31, 31, 0.45);
	}
}
.view-user__btn{
	display: flex;
	justify-content: center;
	align-items: center;
	width: 140rpx;
	height: 56rpx;
	font-size: 24rpx;
	font-family: Helvetica-Bold, Helvetica;
	font-weight: bold;
	color: #0078FF;
	border-radius: 36rpx;
	border: 1px solid #0078FF;
}
.content-list {
	padding: 30rpx;
	box-sizing: border-box;
	padding-bottom: 160rpx;
	.content-item {
		background-color: #fff;
		padding: 32rpx 40rpx;
		box-shadow: 0px 4px 12px 0px rgba(55, 58, 64, 0.08);
		border-radius: 4px;
		box-sizing: border-box;
		position: relative;
		margin-bottom: 16rpx;
		.content-list__title {
			height: 80rpx;
			display: flex;
			justify-content: flex-start;
			align-items: flex-start;
			font-size: 32rpx;
			font-family: Helvetica;
			color: #1F1F1F;
			margin-bottom: 8rpx;
		}
		.content-list__text {
			margin: 32rpx;
			font-size: 30rpx;
			font-family: Helvetica;
			color: #1F1F1F;
		}
		.content-list__title-time {
			font-size: 22rpx;
			font-family: Helvetica;
			color: rgba(31, 31, 31, 0.45);
		}
		.content-list__title-img {
			width: 80rpx;
			height: 80rpx;
			margin-right: 20rpx;
			border-radius: 50%;
		}
	}
}
.content-list__imgs {
	display: flex;
	justify-content: flex-start;
	align-items: flex-start;
	margin-bottom: 32rpx;
	.content-list__imgs-item {
		width: 190rpx;
		height: 190rpx;
		border-radius: 8rpx;
		background-color: #000;
		margin-right: 18rpx;
	}
}
.content-list__btns {
	display: flex;
	justify-content: flex-start;
	align-items: center;
	font-size: 28rpx;
	font-family: Helvetica;
	color: rgba(31, 31, 31, 0.45);
	.content-list__btns-img {
		width: 48rpx;
		height: 48rpx;
		margin-right: 8rpx;
	}
}
.content-list__official {
	position: absolute;
	top: 0;
	right: 0;
	font-size: 20rpx;
	.content-list__o {
		width: 96rpx;
		height: 96rpx;
		top: 0;
		right: 0;
	}
	.content-list__t {
		transform: rotate(42deg);
		position: absolute;
		top: 10px;
		right: 0;
		color: #fff;
	}
}
</style>
